import QtQuick
import QtQuick.Controls

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    ProgressBar {
        id: animatedProgressBar
        anchors.centerIn: parent
        width: 300
        value: 0

        background: Rectangle {
            implicitWidth: 300
            implicitHeight: 20
            color: "#e0e0e0"
            radius: 10
        }

        contentItem: Item {
            implicitWidth: 300
            implicitHeight: 20

            Rectangle {
                width: animatedProgressBar.visualPosition * parent.width
                height: parent.height
                color: "#21be2b"
                radius: 10

                Behavior on width {
                    NumberAnimation { duration: 500 }  // 添加宽度变化的动画效果
                }
            }
        }
    }

    Timer {
        interval: 1000
        running: true
        repeat: true
        onTriggered: {
            if (animatedProgressBar.value < 1) {
                animatedProgressBar.value += 0.1;
            } else {
                animatedProgressBar.value = 0;
            }
        }
    }
}
